package org.weasel.unittests;

import java.sql.Time;
import java.util.ArrayList;

import junit.framework.TestCase;

import org.weasel.business.Developer;
import org.weasel.business.Project;
import org.weasel.business.Unscheduled;
import org.weasel.business.UserStory;
import org.weasel.business.Utilities;

public class UnscheduledTest extends TestCase {
	private final String xmlFileLoc = "./testfolder/UnscheduledTest.xml";
	private Unscheduled unsch;
	
	@Override
	protected void setUp() throws Exception {
		super.setUp();
		Developer developer = new Developer("9999999", "developer", "mail", "position");
		ArrayList<Developer> allDevelopers = new ArrayList<Developer>();
		allDevelopers.add(developer);
		Project project = new Project(Utilities.createUniqueId(), "my project", xmlFileLoc, allDevelopers);
		unsch = project.getUnscheduled();
	}

	@Override
	protected void tearDown() throws Exception {
		super.tearDown();
		unsch = null;
		Utilities.deleteFile(xmlFileLoc);
	}

	public void testUnscheduledUserStories() throws Exception {
		String id = Utilities.createUniqueId();
		
		UserStory story = unsch.addUnscheduledUserStory(new UserStory(id,"my story", 5, Time.valueOf("13:00:00"), Time.valueOf("14:00:00"), 5, null, null));
		
		UserStory storyCheck = unsch.getUnscheduledUserStory(story.getId());
		
		assertEquals("expected story id " + id, story.getId(), storyCheck.getId());
		assertEquals("expected story name 'my story'", story.getName(), storyCheck.getName());
	}
	
	public void testRemoveUnscheduledUserStory() throws Exception {
		String id = Utilities.createUniqueId();
		
		UserStory story = unsch.addUnscheduledUserStory(new UserStory(id,"my story", 5, Time.valueOf("13:00:00"), Time.valueOf("14:00:00"), 5, null, null));
		unsch.removeUnscheduledUserStory(story.getId());
		
		assertEquals("expected a null value", null, unsch.getUnscheduledUserStory(story.getId()));
	}

}
